begintownscript;

variables;
short choice;
short safety = 0;
short pc_counter;

body;

beginstate 0; //INIT_STATE

	safety = 0;

	//lump all the Loyalists into one group (boo profiling!)
	add_range_to_group(6,18,1);
	
	//if the jig is up, set them to be hostile
	if(get_flag(5,1) == 1) {
		safety = 1;
		set_attitude(1001,10);
		}
	
	//if Trevahn is dead, erase all the Loyalists
	if(get_flag(7,3) >= 1) {
		erase_char(1001);
		//one-shot dialog
		if(get_flag(5,0) == 0) {
			message_dialog("Now that the Loyalists have fled, it sure is a lot quieter around here.","");
			set_flag(5,0,1);
			}
		}
	
break;

beginstate 1; //EXIT_STATE
break;

beginstate 2; //START_STATE
	//Checking for the lead pc each turn... not necessary here
	//pc_counter = 0;
	//while(char_ok(pc_counter) == 0) {
	//	pc_counter = pc_counter + 1;
	//	}
	//lead_char = pc_counter;
	
	
	
	//if the Loyalists have been cleared out, skip ALL of this
	if(get_flag(8,0) == 1)
		end();
	
	//check to see if party has Darkside armor equipped
	// ...only runs if the jig is not up
	if((get_flag(5,1) == 0) && (safety == 0)) {

		//if in combat, the jig is up automatically
		if(is_combat() == 1) {
			safety = 1;
			set_flag(5,1,1);
			message_dialog("One of the Loyalists notices that you've drawn your weapons, and shouts an alarm. Not good.","");
			set_attitude(1001,10);
			alert_char(1001);
			}
		pc_counter = 0;
		//armor check
		while((pc_counter < 4) && (safety == 0)) {
			if((char_ok(pc_counter) == 1) && (item_type_in_slot(pc_counter,0) != 447))
				safety = 1; //not safe if armor isn't equipped
			pc_counter = pc_counter + 1;
			}
		}
	//if the jig is up, trigger the message
	if((get_flag(5,1) == 0) && (safety == 1)) {
		reset_dialog();
		add_dialog_str(0,"One of the Loyalists spots you and shouts an alarm. Not good.",0);
		run_dialog(1);
		set_flag(5,1,1);
		set_attitude(1001,10);
		alert_char(1001);
		}
			
	//if the jig is up but nobody's hostile for some reason, make it so
	// (this can happen if the jig is upped by the loyalist script)
	if((get_flag(5,1) == 1) && (get_attitude(first_group_member(1)) != 10)) {
		set_attitude(1001,10);
		alert_char(1001);
		}
	
break;

beginstate 10; //signal fire
	if(get_flag(5,3) == 1)
		end();
	if(get_flag(2,1) == 1)
		message_dialog("This is a signal fire, just like the one at the docks back by Stonesthrow.","It's not lit, but you're not surprised.");
	else {
		message_dialog("You recognize this platform as a signal fire, a common safety feature on almost all Empire docks.","It's not lit, but you're not surprised.");
		set_flag(2,1,1);
		}
	set_flag(5,3,1);
break;

beginstate 15; //burned documents
	if(get_flag(5,4) == 1)
		end();
	reset_dialog();
	add_dialog_str(0,"It looks like the contents of these shelves were burnt. A thin layer of ash covers the floor around you.",0);
	add_dialog_str(1,"You wonder if they were burnt before or after the Loyalists showed up.",0);
	run_dialog(1);
	set_flag(5,4,1);
break;